using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace kb_24_the_game
{
    internal class MainMenu
    {
        #region Variabele declaratie

        private Texture2D achtergrond;

        public GraphicsDevice graphics { get; set; }

        public SpriteBatch spriteBatch { get; set; }

        public ContentManager content { get; set; }

        public bool isExitClicked = false, isStartClicked = false;
        private Vector2 sizeStop, positionStop;
        private Vector2 sizeStart, positionStart;
        private Rectangle exitKnop;
        private Rectangle startKnop;
        private Texture2D textureStop;
        private Texture2D textureStart;
        private Color kleurExitKnop, kleurStartKnop;
        private float middenX;

        #endregion Variabele declaratie

        public void Load()
        {
            achtergrond = content.Load<Texture2D>("MainMenu/MainMenu");
            middenX = (graphics.Viewport.Width / 2);
            LaadExitKnop();
            LaadStartKnop();
        }

        private void LaadStartKnop()
        {
            textureStart = content.Load<Texture2D>("MainMenu/startKnop");
            sizeStart = new Vector2(graphics.Viewport.Width / 4, graphics.Viewport.Height / 22);
            positionStart = new Vector2(middenX - textureStart.Width / 2, 400);
            startKnop = new Rectangle((int)positionStart.X, (int)positionStart.Y, (int)sizeStart.X, (int)sizeStart.Y);
        }

        private void LaadExitKnop()
        {
            textureStop = content.Load<Texture2D>("MainMenu/exitKnop");
            sizeStop = new Vector2(graphics.Viewport.Width / 4, graphics.Viewport.Height / 22);
            positionStop = new Vector2(middenX - (textureStop.Width / 2), 500);
            exitKnop = new Rectangle((int)positionStop.X, (int)positionStop.Y, (int)sizeStop.X, (int)sizeStop.Y);
        }

        public void Update(MouseState mouse)
        {
            isExitClicked = false;
            isStartClicked = false;
            Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);
            if (mouseRectangle.Intersects(exitKnop))
            {
                kleurExitKnop = Color.Cyan;
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    isExitClicked = true;
                }
            }
            else
            {
                kleurExitKnop = Color.White;
                isExitClicked = false;
            }
            if (mouseRectangle.Intersects(startKnop))
            {
                kleurStartKnop = Color.Cyan;
                if (mouse.LeftButton == ButtonState.Pressed)
                {
                    isStartClicked = true;
                }
            }
            else
            {
                kleurStartKnop = Color.White;
                isStartClicked = false;
            }
        }

        public void Draw()
        {
            spriteBatch.Draw(achtergrond, new Rectangle(0, 0, graphics.Viewport.Width, graphics.Viewport.Height), Color.White);
            DrawExitKnop();
            DrawStartKnop();
        }

        private void DrawStartKnop()
        {
            spriteBatch.Draw(textureStart, startKnop, kleurStartKnop);
        }

        private void DrawExitKnop()
        {
            spriteBatch.Draw(textureStop, exitKnop, kleurExitKnop);
        }
    }
}